package org.elepower.controller;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.apache.ibatis.annotations.Param;
import org.elepower.dao.SystemConfigDao;
import org.elepower.pojo.PsSysteamconfig;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/bugType")
public class BugTypeController {
    @Autowired
    private SystemConfigDao systemConfigDao;

    @RequestMapping("/index")
    public String index() throws Exception{
        return "system/bugType/index";
    }

    @RequestMapping("/selectInfo")
    @ResponseBody
    public Map<String,Object> selectInfo(@RequestParam(defaultValue = "1") Integer page,@RequestParam(defaultValue = "10")Integer limit) throws Exception{
        Map<String,Object> map = new HashMap<>();
        Page<PsSysteamconfig> pager = PageHelper.startPage(page,limit);
        List<PsSysteamconfig> systeamconfigList = systemConfigDao.getBugType();

        map.put("count",pager.getTotal());
        map.put("data",systeamconfigList);
        map.put("code",0);
        map.put("msg","");

        return map;
    }

    @RequestMapping("/form")
    public String form() throws Exception{
        return "system/bugType/form";
    }

    @RequestMapping("/update")
    @ResponseBody
    public Map<String,Object> update(PsSysteamconfig systeamconfig) throws Exception{
        Map<String,Object> map = new HashMap<>();
        systeamconfig.setConfigCode("BUG_TYPE");
        systeamconfig.setConfigName("缺陷类型");

        if(systeamconfig.getIsStart() == null){
            systeamconfig.setIsStart(0);
        }

        systemConfigDao.update(systeamconfig);

        map.put("result",true);
        return map;
    }

    @RequestMapping("/del")
    @ResponseBody
    public Map<String,Object> del(Integer id) throws Exception{
        Map<String,Object> map = new HashMap<>();

        systemConfigDao.del(id);

        map.put("result",true);
        return map;
    }

    @RequestMapping("/add")
    @ResponseBody
    public Map<String,Object> add(PsSysteamconfig psSysteamconfig) throws Exception{
        Map<String,Object> map = new HashMap<>();
        psSysteamconfig.setConfigCode("BUG_TYPE");
        psSysteamconfig.setConfigName("缺陷类型");
        if(psSysteamconfig.getIsStart() == null){
            psSysteamconfig.setIsStart(0);
        }
        systemConfigDao.add(psSysteamconfig);
        map.put("result",true);
        return map;
    }

    @RequestMapping("/get")
    @ResponseBody
    public PsSysteamconfig get(Integer id) throws Exception{
        return systemConfigDao.get(id);
    }
}
